home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 July: Mac OS SDK / Dev.CD Jul 99 SDK1.toast / Development Kits / Mac OS / QuickDraw3D 1.6 SDK / Mac SampleCode New for 1.6 / ViewerOptBtnSample / Source / Misc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-05-18  |  2.0 KB  |  109 lines  |  [TEXT/CWIE]

  1. /****************************/
  2. /*      MISC ROUTINES       */
  3. /* By Brian Greenstone      */
  4. /****************************/
  5.  
  6.  
  7. /***************/
  8. /* EXTERNALS   */
  9. /***************/
  10. #include <Events.h>
  11. #include <Dialogs.h>
  12. #include <NumberFormatting.h>
  13.  
  14. #include <QD3D.h>
  15. #include <QD3DErrors.h>
  16.  
  17. #include "myglobals.h"
  18. #include "misc.h"
  19.  
  20.  
  21. /****************************/
  22. /*    CONSTANTS             */
  23. /****************************/
  24.  
  25. #define        ERROR_ALERT_ID        401
  26.  
  27. /**********************/
  28. /*     VARIABLES      */
  29. /**********************/
  30.  
  31.  
  32. /****************** DO SYSTEM ERROR ***************/
  33.  
  34. void ShowSystemErr(long err)
  35. {
  36. Str255        numStr;
  37.  
  38.     NumToString(err, numStr);
  39.     DoAlert (numStr);
  40.     CleanQuit();
  41. }
  42.  
  43. /*********************** DO ALERT *******************/
  44.  
  45. void DoAlert(Str255 s)
  46. {
  47.     ParamText(s,NIL_STRING,NIL_STRING,NIL_STRING);
  48.     NoteAlert(ERROR_ALERT_ID,nil);
  49. }
  50.         
  51. /*********************** DO FATAL ALERT *******************/
  52.  
  53. void DoFatalAlert(Str255 s)
  54. {
  55.     ParamText(s,NIL_STRING,NIL_STRING,NIL_STRING);
  56.     NoteAlert(ERROR_ALERT_ID,nil);
  57.     CleanQuit();
  58. }
  59.  
  60. /************ CLEAN QUIT ***************/
  61.  
  62. void CleanQuit(void)
  63. {
  64.     ExitToShell();
  65. }
  66.  
  67.  
  68.  
  69. /******************* FLOAT TO STRING *******************/
  70.  
  71. void FloatToString(float num, Str255 string)
  72. {
  73. Str255    sf;
  74. long    i,f;
  75.  
  76.     i = num;                        // get integer part
  77.     
  78.     
  79.     f = (fabs(num)-fabs((float)i)) * 10000;        // reduce num to fraction only & move decimal --> 5 places    
  80.  
  81.     if ((i==0) && (num < 0))        // special case if (-), but integer is 0
  82.     {
  83.         string[0] = 2;
  84.         string[1] = '-';
  85.         string[2] = '0';
  86.     }
  87.     else
  88.         NumToString(i,string);        // make integer into string
  89.         
  90.     NumToString(f,sf);                // make fraction into string
  91.     
  92.     string[++string[0]] = '.';        // add "." into string
  93.     
  94.     if (f >= 1)
  95.     {
  96.         if (f < 1000)
  97.             string[++string[0]] = '0';    // add 1000's zero
  98.         if (f < 100)
  99.             string[++string[0]] = '0';    // add 100's zero
  100.         if (f < 10)
  101.             string[++string[0]] = '0';    // add 10's zero
  102.     }
  103.     
  104.     for (i = 0; i < sf[0]; i++)
  105.     {
  106.         string[++string[0]] = sf[i+1];    // copy fraction into string
  107.     }
  108. }
  109.